from rest_framework import serializers
from .models import Area

"""
查询所有省时用的是AreaSerializer
查询单一省时 SubsSerializer代表单个省 --》 AreaSerializer 省下面的所有市
查询单一市时 SubsSerializer代表单个市 --》 AreaSerializer 市下面的所有区
"""

class AreaSerializer(serializers.ModelSerializer):
    """省的序列化器"""

    class Meta:
        model = Area
        fields = ['id', 'name']

class SubsSerializer(serializers.ModelSerializer):
    # 130000
    # 河北省模型. subs.all()
    """详情试图使用序列化器"""
    #采用关联序列化
    subs = AreaSerializer(many=True)
    class Meta:
        model = Area
        fields = ['id', 'name', 'subs']
